<%
layout("/include/_dialog.html"){
%>
	<script type="text/javascript">

        function save() {
            var isValidate = jp.validateForm('#inputForm');//校验表单
            if(!isValidate){
                return false;
            }else{
                //功能权限
                var ref = $('#menuTree').jstree(true);
                var ids = ref.get_selected();
                //取半选节点ID
                $("#menuTree li").has("i[class*='jstree-undetermined']").each(function(){
                    ids+=","+$(this).attr("id");
                });
                $("#menuIds").val(ids);

                //数据权限
                var data_ref = $('#dataRuleTree').jstree(true);
                var nodes = data_ref.get_selected(true);
                var data_ids = new Array();
                for(var i=0; i<nodes.length; i++){
                    if(nodes[i].original.type==='4'){
                        data_ids.push(nodes[i].id);
                    }
                }
                $("#dataRuleIds").val(data_ids.join(","));
                jp.loading();
                jp.post("${ctx}/sys/role/save",$('#inputForm').serialize(),function(data){
                    if(data.success){
                        // jp.getParent().refresh();
                        var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(dialogIndex);
                        jp.success(data.msg)

                    }else{
                        jp.error(data.msg);
                    }
                })
            }

        }
		$(document).ready(function(){
		
			//功能权限
			$('#menuTree').jstree({
				'core' : {
					"multiple" : true,
					"animation" : 0,
					"themes" : { "icons":true ,"stripes":false, "responsive": false},
					'data' : {
						"url" : "${ctx}/sys/menu/treeData?roleId=${role.id}",
						"dataType" : "json" // needed only if you do not supply JSON headers
					}
				},
				'plugins': ["wholerow", "checkbox", "types"],
				"types": {
					"default": {
						"icon": "fa fa-folder text-custom"
					},
					"file": {
						"icon": "fa fa-file text-success"
					},
					'html' : {
						'icon' : 'fa fa-file-code-o'
					},
					'btn':{'icon' : 'fa fa-square'}
				},
				'checkbox' : {
	                // 禁用级联选中  
	                'three_state' : false,       
	                'cascade' : 'undetermined|down|up' //有三个选项，up, down, undetermined; 使用前需要先禁用three_state  
	            },  

			});
			//数据权限
			$('#dataRuleTree').jstree({
				'core' : {
					"multiple" : true,
					"animation" : 0,
					"themes" : { "icons":true ,"stripes":false, "responsive": false},
					'data' : {
						"url" : "${ctx}/sys/dataRule/treeData?roleId=${role.id}",
						"dataType" : "json" // needed only if you do not supply JSON headers
					}
				},
				'plugins' : [ "checkbox", 'types' , 'wholerow'],
				"types": {
					"default": {
						"icon": "fa fa-folder text-custom"
					},
					"file": {
						"icon": "fa fa-file text-success"
					}
				},
				'checkbox' : {  
	                // 禁用级联选中  
	                'three_state' : false,       
	                'cascade' : 'undetermined|down|up' //有三个选项，up, down, undetermined; 使用前需要先禁用three_state  
	            },  

			});

			
		});
		
	</script>
	<div class="p-5">
		<ul class="nav nav-tabs mt-2" role="tablist">
			<li class="nav-item">
				<a class="nav-link show active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">
					<span>功能权限：</span>
				</a>
			</li>
			<li class="nav-item">
				<a class="nav-link show" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">
					<span>数据权限：</span>
				</a>
			</li>
		</ul>

		<div class="tab-content" >
			<div class="tab-pane show active fade in" id="home" role="tabpanel" aria-labelledby="home-tab">
				<div id="menuTree"></div>
			</div>
			<div class="tab-pane show fade in" id="profile" role="tabpanel" aria-labelledby="profile-tab">
				<div id="dataRuleTree"></div>
			</div>
		</div>
	</div>
	<form id="inputForm" action="${ctx}/sys/role/save" method="post" class="form-horizontal">
		<input type="hidden" name="id" id="id" value="${role.id}">
		<input  name="office.id" type="hidden" value="${role.office.id}">
		<input  name="office.name" type="hidden" value="${role.office.name}">
		<input  name="name" type="hidden" value="${role.name}">
		<input  name="oldName" type="hidden" value="${role.name}">
		<input  name="enname" type="hidden" value="${role.enname}">
		<input  name="oldEnname" type="hidden" value="${role.enname}">
		<input  name="roleType" type="hidden" value="${role.roleType}">
		<input  name="sysData" type="hidden" value="${role.sysData}">
		<input  name="useable" type="hidden" value="${role.useable}">
		<input  name="remarks" type="hidden" value="${role.remarks}">
		<input type="hidden" id="menuIds" name="menuIds" value="${role.menuIds}">
		<input type="hidden" id="dataRuleIds" name="dataRuleIds" value="${role.dataRuleIds}">
	</form>

<% } %>